﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using GameLib;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

namespace DustGame {
    class ProductionScreen : GameScreen {
        Viewport viewport;
        Vector2 viewportSize;
        Vector2 v2 = Vector2.Zero;

        List<string> elements = new List<string>(new string[] { "Tank", "Fighter", "Submarine", "Mech", "Bomber", "Production", "Card" });
        int[] elementsCost = new int[] { 2, 3, 4, 5, 6, 6, 1 };

        #region Initialization

        public ProductionScreen() {
            IsPopup = true;

            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.2);
        }

        /// <summary>
        /// Loads graphics content for this screen. This uses the shared ContentManager
        /// provided by the Game class, so the content will remain loaded forever.
        /// Whenever a subsequent MessageBoxScreen tries to load this same content,
        /// it will just get back another reference to the already loaded data.
        /// </summary>
        public override void LoadContent() {
            ContentManager content = ScreenManager.Game.Content;
        }

        public override void UnloadContent() {
            base.UnloadContent();
        }
        #endregion


        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) {
            viewport = ScreenManager.GraphicsDevice.Viewport;
            viewportSize = new Vector2(viewport.Width, viewport.Height);

            // utiliser pour center l'affichage
            v2.X = viewport.TitleSafeArea.Left + 96;
            v2.Y = (viewport.Height / 2) - 96;

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        #region Handle Input


        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input) {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) {
                ExitScreen();
            }
            else if (input.IsNewKeyPress(Keys.Left, ControllingPlayer, out playerIndex) ||
                input.IsNewButtonPress(Buttons.RightThumbstickLeft, ControllingPlayer, out playerIndex) ||
                input.IsNewButtonPress(Buttons.DPadLeft, ControllingPlayer, out playerIndex)) {
                #region navigation gauche inventaire
                #endregion
            }
            else if (input.IsNewKeyPress(Keys.Right, ControllingPlayer, out playerIndex) ||
                input.IsNewButtonPress(Buttons.RightThumbstickRight, ControllingPlayer, out playerIndex) ||
                input.IsNewButtonPress(Buttons.DPadRight, ControllingPlayer, out playerIndex)) {
                #region navigation droite inventaire
                #endregion
            }
            else if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) {
            }
        }


        #endregion

        #region Draw


        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime) {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = Fonts.Message;
            Vector2 offset = Vector2.Zero;


            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            // Fade the popup alpha during transitions.
            Color color = new Color(Color.White, TransitionAlpha);
            float transitionOffset = (float)Math.Pow(TransitionPosition, 2);
            if (ScreenState == ScreenState.TransitionOn)
                v2.X -= transitionOffset * 256;
            else
                v2.X += transitionOffset * 256;


            spriteBatch.Begin();

            for (int i = 0; i < elements.Count; i++) {
                spriteBatch.DrawString(font, elements[i], v2 + new Vector2(0, (i * font.LineSpacing)), Color.White);
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
        #endregion
    }
}
